package com.gjzt.business.bid.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eastdigit.servlet.ReqBean;
import com.eastdigit.servlet.RequestAttribute;
import com.eastdigit.servlet.Response;
import com.gjzt.business.bid.service.BiddingForExternalService;
import com.gjzt.business.bid.service.BiddingService;

import net.sf.json.JSONObject;


/**
 * 对外广告资源平台后台调用controller
 * 
 * 反问地址带anon表示用户无需登录即可反问
 * @author zwm
 *
 */

@Controller
@RequestMapping(value = "")
public class BiddingForExternalController {

    @Autowired
    private BiddingForExternalService biddingForExternalService;
    @Autowired
    private BiddingService biddingService;

    /**
     * 查询
     *
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/anon/www/bid/query")
    @ResponseBody
    public JSONObject queryAdBidding(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.findAdBidding(reqBean));
    }
    
    /**
     * 根据id查询竞价信息
     * 
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/anon/www/bid/findBidByBidId")
    @ResponseBody
    public JSONObject findBidByBidId(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.findBidByBidId(reqBean));
    }
    
    /**
     * 查询出价信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/anon/www/bid/findBidRecordInfo")
    @ResponseBody
    public JSONObject findBidRecordInfo(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.findBidRecordInfo(reqBean));
    }
    
    
    /**
     * 查询客户所购买资源信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/bid/findCustomerResource")
    @ResponseBody
    public JSONObject findCustomerResource(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.findCustomerResource(reqBean));
    }
    
    
    /**
     * 获得客户参与过竞价的信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/bid/getCustomerBidsInfo")
    @ResponseBody
    public JSONObject getCustomerBidsInfo(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.getCustomerBidsInfo(reqBean));
    }
    
    /**
     * 查询客户保证金信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/anon/www/bid/getCustomerDeposit")
    @ResponseBody
    public JSONObject getCustomerDeposit(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.getCustomerDeposit(reqBean));
    }
    
    /**
     * 查询客户支付中的订单信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/anon/www/bid/getCustomerDepositOrder")
    @ResponseBody
    public JSONObject getCustomerDepositOrder(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.getCustomerDepositOrder(reqBean));
    }
    
/*    *//**
     * 客户交保证金
     * @param reqBean
     * @return
     * @throws IOException 
     * @throws ServletException 
     *//*
	@RequestMapping(value = "/www/bid/payDeposit")
	@ResponseBody
	public void payDeposit(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException {
		// biddingForExternalService.payDeposit(reqBean);
		frontConsume.payDeposit(reqBean,req, resp);
	}
	*/
    /**
     * 客户出价
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/bid/offerPrice")
    @ResponseBody
    public JSONObject offerPrice(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
    	biddingForExternalService.offerPrice(reqBean);
        return Response.responseSuccess();
    }
    
    
    /**
     * 查询客户上刊单信息
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/publishBill/findAdPublishBill")
    @ResponseBody
    public JSONObject findAdPublishBill(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.findAdPublishBill(reqBean));
    }
    
    
    /**
     * 制作单查询
     * @param reqBean
     * @return
     */
   /* @RequestMapping(value = "/www/publishBill/queryMakeBill")
    @ResponseBody
    public JSONObject queryMakeBill(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.queryMakeBill(reqBean));
    }*/


    /**
     * 制作单信息查询（包含制作单明细）
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/publishBill/queryMakeBillInfo")
    @ResponseBody
    public JSONObject queryMakeBill(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.queryMakeBillInfo(reqBean));
    }
    /**
     * 制作单明细
     * @param reqBean
     * @return
     */
   /* @RequestMapping(value = "/www/publishBill/queryMakeBillDetails")
    @ResponseBody
    public JSONObject queryMakeBillDetails(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingForExternalService.queryMakeBillDetails(reqBean));
    }*/
    
    /**
     * 完工时间、图片处理
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/publishBill/completeBill")
    @ResponseBody
    public JSONObject completeBill(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
    	biddingForExternalService.completeBill(reqBean);
        return Response.responseSuccess();
    }
    
    
    /**
     *  全部完工
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/www/publishBill/finishAll")
    @ResponseBody
    public JSONObject finishAll(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
    	biddingForExternalService.finishAll(reqBean);
        return Response.responseSuccess();
    }
    
    /**
     * 查询竞价包含的资源(按资源类型分类)
     *
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/anon/www/bid/getBidResourceGroupByTypes")
    @ResponseBody
    public JSONObject getBidResourceTypes(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(biddingService.getBidResourceGroupByTypes(reqBean));
    }
    
    //TODO 其他功能
}